#页面元素和属性分离，元素放在xml文件里
import xml.etree.ElementTree as Et
from web.config.config import Config

tree = Et.ElementTree(file=Config().elementFile)
class LoginLocator:
    @property
    def username_loc(self):
        #从xml文件中读取元素定位信息
        p = tree.find('./登录页/用户名').get('property')
        v = tree.find('./登录页/用户名').get('value')

        #从数据库中读取元素定位信息
        #......
        return {p: v}

    @property
    def password_loc(self):
        p = tree.find('./登录页/密码').get('property')
        v = tree.find('./登录页/密码').get('value')
        return {p: v}

    @property
    def submit_loc(self):
        p = tree.find('./登录页/立即登录').get('property')
        v = tree.find('./登录页/立即登录').get('value')
        return {p: v}

    @property
    def prompt_loc(self):
        p = tree.find('./登录页/提示信息').get('property')
        v = tree.find('./登录页/提示信息').get('value')
        return {p: v}

    @property
    def exit_loc(self):
        p = tree.find('./登录页/退出').get('property')
        v = tree.find('./登录页/退出').get('value')
        return {p: v}


class IndexSerarchLocator:
    @property
    def category_loc(self):
        p = tree.find('./首页检索/分类下拉框').get('property')
        v = tree.find('./首页检索/分类下拉框').get('value')
        return {p: v}

    @property
    def keyword_loc(self):
        p = tree.find('./首页检索/搜索内容').get('property')
        v = tree.find('./首页检索/搜索内容').get('value')
        return {p: v}

    @property
    def search_loc(self):
        p = tree.find('./首页检索/搜索按钮').get('property')
        v = tree.find('./首页检索/搜索按钮').get('value')
        return {p: v}

class RegisterLocator:
    @property
    def username_loc(self):
        p = tree.find('./注册页/用户名').get('property')
        v = tree.find('./注册页/用户名').get('value')
        return {p: v}
    @property
    def email_loc(self):
        p = tree.find('./注册页/email').get('property')
        v = tree.find('./注册页/email').get('value')
        return {p: v}
    @property
    def password1_loc(self):
        p = tree.find('./注册页/密码').get('property')
        v = tree.find('./注册页/密码').get('value')
        return {p: v}
    @property
    def conformpassword_loc(self):
        p = tree.find('./注册页/确认密码').get('property')
        v = tree.find('./注册页/确认密码').get('value')
        return {p: v}
    @property
    def MSN_loc(self):
        p = tree.find('./注册页/MSN').get('property')
        v = tree.find('./注册页/MSN').get('value')
        return {p: v}
    @property
    def QQ_loc(self):
        p = tree.find('./注册页/QQ').get('property')
        v = tree.find('./注册页/QQ').get('value')
        return {p: v}
    @property
    def OfficePhone_loc(self):
        p = tree.find('./注册页/办公电话').get('property')
        v = tree.find('./注册页/办公电话').get('value')
        return {p: v}
    @property
    def familyPhone_loc(self):
        p = tree.find('./注册页/家庭电话').get('property')
        v = tree.find('./注册页/家庭电话').get('value')
        return {p: v}
    @property
    def MobilePhone_loc(self):
        p = tree.find('./注册页/手机').get('property')
        v = tree.find('./注册页/手机').get('value')
        return {p: v}
    @property
    def question_loc(self):
        p = tree.find('./注册页/密码提示问题').get('property')
        v = tree.find('./注册页/密码提示问题').get('value')
        return {p: v}
    @property
    def passwdAnswer_loc(self):
        p = tree.find('./注册页/密码问题答案').get('property')
        v = tree.find('./注册页/密码问题答案').get('value')
        return {p: v}
    @property
    def Submit_loc(self):
        p = tree.find('./注册页/立即注册').get('property')
        v = tree.find('./注册页/立即注册').get('value')
        return {p: v}

registerLocator = RegisterLocator()
loginLocator = LoginLocator()
indexSerarchLocator = IndexSerarchLocator()